package com.md.yleducationsupervisor

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentPagerAdapter
import android.view.View
import android.widget.CompoundButton
import com.md.base.BaseActivity
import com.md.fragment.F1Fragment
import com.md.fragment.F2Fragment
import com.md.fragment.F3Fragment
import com.md.nohttp.Params.stedatas
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseActivity() {
    private lateinit var fragment: Fragment
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        stedatas()
        init()
        rb_1.performClick()
    }

    private fun init() {
        rb_1.setOnCheckedChangeListener(this)
        rb_2.setOnCheckedChangeListener(this)
        rb_3.setOnCheckedChangeListener(this)
    }


    override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) {
        super.onCheckedChanged(buttonView, isChecked)
        if (isChecked) {
            fragment = mFragmentPagerAdapter
                .instantiateItem(fragment_container, buttonView.id) as Fragment
            mFragmentPagerAdapter.setPrimaryItem(fragment_container, 0, fragment)
            mFragmentPagerAdapter.finishUpdate(fragment_container)
        }
    }

    private val mFragmentPagerAdapter = object : FragmentPagerAdapter(supportFragmentManager) {

        override fun getItem(position: Int): Fragment = when (position) {
            R.id.rb_1 -> F1Fragment()
            R.id.rb_2 -> F2Fragment()
            R.id.rb_3 -> F3Fragment()
            else -> F1Fragment()
        }

        override fun getCount(): Int = 3
    }


    override fun onClick(view: View) {
        when (view.id) {
            R.id.ll_setting -> {//
                StartActivity(SettingActivity::class.java)
            }
            R.id.ll_version -> {//已购课程
            }
            R.id.ll_code -> {//已购课程
            }
            R.id.ll_sex -> {//已购课程
            }
            R.id.ll_phone -> {//已购课程
            }
            R.id.ll_name -> {//已购课程
            }
        }
    }
}
